#ifndef CLIREADE_H
#define CLIREADE_H

#include <QString>
#include <QFile>
#include <QTextStream>
#include <QObject>
#include "CliDefinition.h"

#define CLIREAD HIM::CLIRead::getInstance()

namespace HIM {
class CLIRead: public QObject
{
     Q_OBJECT
public:
    static CLIRead& getInstance(){
          static CLIRead instance;
          return instance;
      }

    void clearAll();
    bool readCLIFile(const QString&);

    const CliHeaderData* getCliHeasderData(){
        return &cliHeasderData;
    }

    const CliLayerData* getCliCurruntLayerData(){
        return &cliCurruntLayerData;
    }

    const CliDataIndex* getCliDataIndex(){
        return &cliDataIndex;
    }

    int getCurruntLayerIndex(){
        return curruntLayerIndex;
    }

    bool getCliLoaded(){
        return cliLoaded;
    }

    qint64 getPrintEstimatedTime(){
        return printEstimatedTime_S;
    }

    bool analysisCLIHeader();
    bool analysisCLILayer(int layerIdex);

    bool cliFloatRegex(const QString &str , double &result);
    bool cliFloatsRegex(const QString &str , QVector<double> &result);
    bool cliIntRegex(const QString &str , int &result);
    bool cliIntStrRegex(const QString &str , QPair<int,QString> &result);
    bool cliIntsRegex(const QString &str , QVector<int> &result);

signals:
    void cliReadProgress(int);

private:
    CLIRead():
     cliDataPtr_(new unsigned char)
    {};
    ~CLIRead(){
        delete cliDataPtr_;
    };
    CLIRead(const CLIRead&)=delete ;
    CLIRead& operator=(const CLIRead&)=delete;

private:

    std::shared_ptr<QFile> cliFile_ = std::make_shared<QFile>();
    unsigned char* cliDataPtr_;

    CliHeaderData cliHeasderData;
    CliLayerData cliCurruntLayerData;
    CliDataIndex cliDataIndex;    
    int curruntLayerIndex{0};

    qint64 printEstimatedTime_S{0};

    bool cliLoaded{false};

};

#include <exception>
#include <string>

class CliReadException : public std::exception{
private:
    std::string str;
public:
    CliReadException(std::string s){
        str=s;
    }
    const char * what () const throw () {
         return str.c_str();
      }
};

}

#endif // CLIREADE_H
